package com.xwdeshj.controller;


import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwFarmBasicinfoService;
import com.xwdeshj.utils.IMoocExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


/**
 * Created by BKWJA on 2018/12/24.
 * 农家乐店铺基本信息控制层
 */
@Slf4j
@RequestMapping("farmbusinesinfo")
@CrossOrigin(allowCredentials = "true")
@Controller
public class XwFarmBasicinfoController extends IMoocExceptionHandler {

    @Autowired
    private XwFarmBasicinfoService xwFarmBasicinfoService;

    /**
     * 农家乐信息查询
     * @param pagesize  每页显示多少条记录
     * @param pageindex  当前页
     * @param starttime 开始时间
     * @param endtime  结束时间
     * @param searchval   查询关键字
     * @param searchkey  查询字段名
     * @param sortfild  排序字段
     * @param sortway  排序（升序，降序）
     * @param type  店铺类型
     * @param status  营业类型
     * @return
     */
    @RequestMapping("/getfarminfolist")
    @ResponseBody
    public JSONObject getfarminfolist(@RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                      @RequestParam(value = "pageindex",defaultValue = "1") Integer pageindex,
                                      @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                      @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                      @RequestParam(value = "searchval",defaultValue = "") String searchval,
                                      @RequestParam(value = "searchkey",defaultValue = "") String searchkey,
                                      @RequestParam(value = "sortfild",defaultValue = "farm_createtime") String sortfild,
                                      @RequestParam(value = "sortway",defaultValue = "desc")String sortway,
                                      @RequestParam(value = "type",defaultValue = "")String type,
                                      @RequestParam(value = "status",defaultValue = "")String status,
                                      HttpServletRequest request){
        searchval.trim();
        return xwFarmBasicinfoService.getfarminfolist(pagesize,pageindex,starttime,endtime,searchval,searchkey,
                sortfild,sortway,type,status,request);
    }

    /**
     *  商家详情——获取农家乐基本信息（一条）
     * @param business_encryptId 商家加密id
     * @param farm_encryptId 店铺加密id
     * @param request
     * @return
     */
    @RequestMapping("/getfarminfo")
    @ResponseBody
    public JSONObject getfarminfo(@RequestParam(value = "business_encryptId",defaultValue = "")String business_encryptId,
                                  @RequestParam(value = "farm_encryptId",defaultValue = "")String farm_encryptId,
                                      HttpServletRequest request){
        return xwFarmBasicinfoService.getfarminfo(business_encryptId,farm_encryptId,request);
    }

    /**
     *  修改商家的游玩类型备注
     * @param farm_encryptId 店铺加密id
     * @param farmplay_encryptId  游玩类型加密id
     * @param farmplaymark  游玩类型备注
     * @param request
     * @return
     */
    @RequestMapping("/modifyfarmplayRemarks")
    @ResponseBody
    public JSONObject modifyfarmplayRemarks(@RequestParam(value = "farm_encryptId",defaultValue = "")String farm_encryptId,
                                  String farmplay_encryptId,String farmplaymark,HttpServletRequest request){
        return xwFarmBasicinfoService.modifyfarmplayRemarks(farm_encryptId,farmplay_encryptId,
                farmplaymark,request);
    }

    /**
     * 修改商家基本信息
     * @param business_encryptId 商家加密id
     * @param farm_encryptId 店铺加密id
     * @param updatefiled 修改的字段名
     * @param updateval 修改的内容
     * @param request
     * @return
     */
    @RequestMapping("/updatefarminfo")
    @ResponseBody
    public JSONObject updatefarminfo(@RequestParam(value = "business_encryptId",defaultValue = "")String business_encryptId,
                                     @RequestParam(value = "farm_encryptId",defaultValue = "")String farm_encryptId,
                                            String updatefiled,String updateval,HttpServletRequest request){
        updateval = updateval.trim();
        return xwFarmBasicinfoService.updatefarminfo(business_encryptId,farm_encryptId,updatefiled,updateval,request);
    }




}
